package cn.arnold.offer.qunar.test1;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;


public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        scanner.nextLine();
        String s = scanner.nextLine();
        String s2 = scanner.nextLine();
        String[] yun = s.split(" ");
        String[] chan = s2.split(" ");
        Map<String, Integer> yunMap = new HashMap<>();
        for (int i = 0; i < yun.length; i++) {
            yunMap.put(yun[i], i);
        }
        Map<String, Integer> chanMap = new HashMap<>();
        for (int i = 0; i < chan.length; i++) {
            chanMap.put(chan[i], i);
        }
        int count = 0;
        for (int i = 0; i < yun.length; i++) {
            String pivot = yun[i];
            Integer yunPrio = yunMap.get(pivot);
            Integer chanPrio = chanMap.get(pivot);
            int gap = yunPrio - chanPrio;
            if (Math.abs(gap) == 1) {
                count++;
            }
        }
        System.out.println(count);
    }
}
